fn main() {
    println!("==============================");
    test01_match();
    println!("==============================");
    test02_if_let();
    println!("==============================");
    test03_while_let();
    println!("==============================");
    test04_for();
    println!("==============================");
    test05_let();
    println!("==============================");
    test06_fn();
    println!("==============================");
}

fn test01_match() {
    let x = Some(1);
    let x = match x {
        None => None,
        Some(i) => Some(i + 1),
    };
    println!("{}", x.unwrap());
}

fn test02_if_let() {
    let favorite_color: Option<&str> = None;
    let is_tuesday = false;
    let age: Result<u8, _> = "34".parse();
    if let Some(color) = favorite_color {
        println!("Using your favorite color, {color}, as the background");
    } else if is_tuesday {
        println!("Tuesday is green day!");
    } else if let Ok(age) = age {
        if age > 30 {
            println!("Using purple as the background color");
        } else {
            println!("Using orange as the background color");
        }
    } else {
        println!("Using blue as the background color");
    }
}

fn test03_while_let() {
    let (tx, rx) = std::sync::mpsc::channel();
    let thread1 = std::thread::spawn(move || {
        for val in 1..=3 {
            std::thread::sleep(std::time::Duration::from_millis(500));
            tx.send(val).unwrap();
        }
    });
    while let Ok(value) = rx.recv() {
        println!("{value}");
    }
    thread1.join().unwrap();
}

fn test04_for() {
    let v = vec!['a', 'b', 'c'];
    for (index, value) in v.iter().enumerate() {
        println!("{value} is at index {index}");
    }
}

fn test05_let() {
    let x = 5;
    let (x, y, z) = (1, 2, 3);
}

fn foo(&(x, y): &(i32, i32)) {
    println!("{},{}", x, y);
}
fn test06_fn() {
    let point = (3,5);
    foo(&point);
}
